<p id="notice"><%= notice %></p>

<h1 class="page-header">文章管理</h1>
<div>
  <%= form_tag(search_admin_articles_path,class: 'form-inline',method: :get) do |f| %>
      <div class="form-group">
        <label for="category_id_">分类</label>
        <%= select_tag('category_id[]' ,options_for_select(Category.all.map {|c| [c.name,c.id]},@category_ids),class: 'form-control',multiple:'multiple') %>
      </div>
      <div class="form-group">
        <label for="tag_id_">标签</label>
        <%= select_tag('tag_id[]' ,options_for_select(Tag.all.map {|c| [c.name,c.id]},@tag_ids),class: 'form-control',multiple:'multiple') %>
      </div>
      <button type="submit" class="btn btn-success">查询</button>
      <%= link_to '显示全部',admin_articles_path,method: :get,class: 'btn btn-info' %>
      <%= link_to '新增', new_admin_article_path,class: 'btn btn-primary pull-right' %>
  <% end %>
</div>
<div class="table-responsive">
  <table class="table table-striped">
    <thead>
    <tr>
      <th>#</th>
      <th>title</th>
      <th>分类</th>
      <th>标签</th>
      <th colspan="3">操作</th>
    </tr>
    </thead>
    <tbody>
    <% @articles.each do |article| %>
        <tr>
          <td><%= article.id %></td>
          <td><%=	article.title %></td>
          <td>
            <% article.categories.each do |category| %>
                <span class="label label-success" style="display: inline-block">
                  <%= category.name %>
                </span>
            <% end %>
          </td>
          <td>
            <% article.tags.each do |tag| %>
                <span class="label label-success" style="display: inline-block">
                  <%= tag.name %>
                </span>
            <% end %>
          </td>
          <td><%= link_to '查看', admin_article_path(article) %></td>
          <td><%= link_to '编辑', edit_admin_article_path(article) %></td>
          <td><%= link_to '删除', admin_article_path(article), method: :delete, data: { confirm: 'Are you sure?' } %></td>
        </tr>
    <% end %>
    </tbody>
  </table>
  <%= render partial: 'share/admin_pagination',locals: {pages: @articles},layout: false %>
</div>
